package org.farming;

import org.farming.plants.*;
/**
 * Patches enum
 * @author DEADBEEF
 * @version 0.01a
 * @note The get() method for the settings array can only be called from the ActiveScript
 * @note Other locations will be added in the future
**/
public enum Patches
{

    ARDGOUNE_ALLOTMENT_N     ( "Ardgoune Allotment N",    505, 0, new Allotments() ),
    ARDGOUNE_ALLOTMENT_S     ( "Ardgoune Allotment S",    505, 1, new Allotments() ),
    ARDGOUNE_FLOWER          ( "Ardgoune Flower",         508, 2, new Flowers()    ),
    ARDGOUNE_HERB            ( "Ardgoune Herb",           515, 2, new Herbs()      ),
    CANAFIS_ALLOTMENT_NW     ( "Canafis Allotment NW",    505, 2, new Allotments() ),
    CANAFIS_ALLOTMENT_SE     ( "Canafis Allotment SE",    505, 3, new Allotments() ),
    CANAFIS_FLOWER           ( "Canafirs Flower",         508, 3, new Flowers()    ),
    CANAFIS_HERB             ( "Canafis Herb",            515, 3, new Herbs()      ),
    CATHERBY_ALLOTMENT_N     ( "Catherby Allotment N",    504, 2, new Allotments() ),
    CATHERBY_ALLOTMENT_S     ( "Catherby Allotment S",    504, 3, new Allotments() ),
    CATHERBY_FLOWER          ( "Catherby Flower",         508, 1, new Flowers()    ),
    CATHERBY_HERB            ( "Catherby Herb",           515, 1, new Herbs()      ),
    ETCETERIA_BUSH           ( "Etceteria Bush",          509, 2, new Bushes()     ),
    FALADOR_ALLOTMENT_NW     ( "Falador Allotment NW",    504, 0, new Allotments() ),
    FALADOR_ALLOTMENT_SE     ( "Falador Allotment SE",    504, 1, new Allotments() ),
    FALADOR_FLOWER           ( "Falador Flower",          508, 0, new Flowers()    ),
    FALADOR_HERB             ( "Falador Herb",            515, 0, new Herbs()      ),
    KANDARIN_MONASTERY_BUSH  ( "Kandarin Monastery Bush", 509, 3, new Bushes()     ),
    RIMMINGTON_BUSH          ( "Rimington Bush",          509, 1, new Bushes()     ),
    VARROCK_BUSH             ( "Varrock Bush",            509, 0, new Bushes()     );
    private static int[] settings;
    
    private final String NAME;
    private final int SETTING_ID, BYTE_ID;   
    private final Plants PLANT_TYPE;   

    /**
     * Patches Enum
     * @param name The name of this patch
     * @param settingId The setting storing this patches byte
     * @param byteId The byte required from the setting (we number the bytes right to left with a 0-index).
     * @param plantType The plant type of this plot from org.farming.plants
    **/
    Patches(
        String name,
        int settingId, 
        int byteId, //RTL
        Plants plantType
    ) {
        this.NAME               = name;
        this.SETTING_ID         = settingId;
        this.BYTE_ID            = byteId;
        this.PLANT_TYPE         = plantType;
    }
    //Get methods
    public String toString()            {return NAME;}//Equivalent of name() as name() cannot be overriden
    public int settingId()              {return SETTING_ID;}
    public int byteId()                 {return BYTE_ID;}
    public Plants plantType()           {return PLANT_TYPE;}
    
    /**
     * This method will return the byte for the specified patch when passed the settings array
     * @param settings The settings array from org.powerbot.game.api.methods.Settings.get()
     * @return The byte of data which describes the specified patch
    **/
    public int getByte(int[] settings)
    {
        try
        {
            int setting = settings[SETTING_ID]; //Grab setting
            int byte1 = (setting>>(8*BYTE_ID)); //Grab byte
            return byte1&255;                   //Return and cleanse byte
        }
        catch(Exception e)
        {
            return -1;//Settings could be too short or null
        }
    }
    /**
     * This method will return the byte for the specified patch from the settings array last provided by the setSettings method
     * @return The byte of data which describes the specified patch
    **/
    public int getByte()
    {
        return getByte(settings);
    }
    /**
     * This method stores the passed settings array so that we can save an argument in the non-static getByte methods
     * @param The settings array from org.powerbot.game.api.methods.Settings.get()
    **/
    public static void setSettings(int[] settingsParam)
    {
        settings=settingsParam;
    }
    

}